<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>添加参考数据库</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
		<script type="text/javascript" src="/webapp/js/common/cities.js"></script>
	</head>
	<body>
		<div class="easyui-container-fluid">
            <div class="easyui-panel" style="border: none;">
                <div class="nav" id="nav"></div>
                <div class="easyui-panel" style="border:none;">
                	<form id="ff">
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >*年：</label>
                            <input type="text" class="easyui-textbox" name="year" style="width:174px;" prompt="请输入年份" data-options="required:true"/>
                        </div>
						<div style="margin-bottom:20px;">
                            <label class="item-label" >*周：</label>
                            <input type="text" class="easyui-textbox" name="week" style="width:174px;" prompt="请输入周度" data-options="required:true"/>
                        </div>
                		<div style="margin-bottom:20px;">
                			<label  class="item-label">*匹配品类：</label>
                			<select class="easyui-combobox" id="categoryCode"  required="required" style="width:174px;" name="categoryCode">
                			</select>
                		</div>
                        <div style="margin-bottom:20px;">
                            <label  class="item-label">匹配品牌：</label>
                            <select class="easyui-combobox" id="brandCode" style="width:174px;" name="brandCode">

                            </select>
                        </div>
		                <div style="margin-bottom:20px;">
                            <label class="item-label" >原始品类：</label>
                            <input type="text" class="easyui-textbox" style="width:174px;" name="originalCategory"/>
                        </div>
		                <div style="margin-bottom:20px;">
                            <label class="item-label" >原始品牌：</label>
                            <input type="text" class="easyui-textbox" style="width:174px;" name="originalBrand"/>
                        </div>
                		<div style="margin-bottom:20px;">
                			<label class="item-label">比例系数：</label>
                			<input type="text" class="easyui-textbox" multiline="true" style="width:174px;height:120px;" name="proportion"/>
                		</div>
                		<div style="margin-bottom:20px;">
                			<label class="item-label">京东占比：</label>
                			<input type="text" class="easyui-textbox" multiline="true" style="width:174px;" name="jdZb"/>
                		</div>
                        <div style="margin-bottom:20px;">
                			<label class="item-label">avc销量：</label>
                			<input type="text" class="easyui-textbox" multiline="true" style="width:174px;" name="avcCount"/>
                		</div>
                        <div style="margin-bottom:20px;margin-left:100px;">
                            <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px" onclick="submitForm()">保存</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" style="width:80px;" onclick="clearForm()">取消</a>
                        </div>
                	</form>
                </div>
            </div>
		</div>
	</body>
    <script type="text/javascript">
        var id = getQueryParameter("id");
        $(function(){
            setNav();
            $.when(initBrandallSelect("brandCode"), initCategorySelect("categoryCode")).done(function(){initFormData()});
        });
        function initFormData(){
            if(id){
                $.ajax({
                    url:config.url+"/reference/"+id,
                    type:"GET",
                    dataType:"json",
                    data:JSON.stringify(id),
                    contentType:"application/json;charset=UTF-8",
                    xhrFields:{withCredentials:true},
                    success:function(data){
                        console.log(data);
                        //填充表单
                        if(data){
                            $("#ff").form("load",changeProperty2String(data));
                        }
                    },
                    error:function(){

                    }
                });

            }

        }
        function submitForm(){
            $("#ff").form("submit",{
               onSubmit:function(){
                  var valid = $(this).form('enableValidation').form('validate');
                  if(valid){
                      var mall = getFormData(document.getElementById("ff"));
                      var method = "POST";
                        if(id){
                          method = "PATCH";
                          mall.id = id;
                        }
                      $.ajax({
                         url:config.url+"/reference",
                         type:method,
                         data:JSON.stringify(mall),
                         dataType:'json',
                         contentType:'application/json;charset=UTF-8',
                         beforeSend:function(){
                            $.messager.progress({
                                title:"请稍等",
                                interval:50,
                                text:"操作进行中..."
							});
                         },
                         complete:function(){
                            $.messager.progress("close");
                         },
                         xhrFields:{withCredentials:true},
                          success:function(data){
                              if(data.code == 200){
                                  $.messager.alert("提示","操作成功","info",function(){
                                      window.parent.closeCurrentTab(true);
                                  });
                              }else{
                                  $.messager.alert("错误",data.msg,"error");
                              }
                          },
                          error:function(XMLHttpRequest,textStatus,thrown){
                              $.messager.alert("提示","操作失败","error");
                          }
                      });
                       return false;
                    }
                    return false;
                  
               }
          });
        }
        function clearForm(){
            window.parent.closeCurrentTab();
        }
    </script>
</html>